package com.sense.kukoo.biz_media.model

import com.sense.kukoo.common.media.net.MediaHttpApi
import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.repo.bean.BookItemBean
import com.sense.kukoo.common.repo.bean.QueryPageBean
import com.sense.kukoo.common.repo.bean.ResultBean
import com.sense.kukoo.common.repo.http.KukooHttpManager
import okhttp3.RequestBody

class MediaListModel: BaseMvvmModel() {

    private val TAG: String = javaClass.simpleName

    override fun onModelCleared() {}

    suspend fun bookQueryPage(
        book_id: Long,
        pageIndex: Int,
        pageSize: Int,
        asc: Int,
    ): ResultBean<QueryPageBean<BookItemBean>> {
        val hashMap = HashMap<String, Any>()
        val sort = HashMap<String, Any>()
        val orders = HashMap<String, Any>()
        val query = HashMap<String, Any>()
        val terms = HashMap<String, Any>()
        hashMap.put("pageIndex", pageIndex)
        hashMap.put("pageSize", pageSize)
        hashMap.put("sort", sort)
        sort.put("order", arrayOf(orders))
        orders.put("asc", asc)//是否正序: 0. 否; 1. 是;
        orders.put("name", "chapter")
        hashMap.put("query", query)
        query.put("terms", arrayOf(terms))
        terms.put("field", "book_id")
        terms.put("value", book_id)
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance.createHttpClient(MediaHttpApi::class.java).bookQueryPage(mRequestBody)
    }
}